const toString = Object.prototype.toString;

export function isDate(val: any): boolean {
    return Object.prototype.toString.call(val) === '[object Date]'
}

// export function isObject(val: any): boolean {
//     return val !== null && typeof val === 'object';
// }

/**
 * 是否是普通对象
 * @param val
 */
export function isPlainObject(val: any): val is Object {
    return toString.call(val) === '[object Object]'
}

/**
 * 交叉类型,混合对象
 * @param to
 * @param from 将from拷贝到to中
 */
export function extend<T,U>(to:T,from:U):T & U{
    for (const key in from){
        //to最终要被断言成T&U类型
        ;(to as T & U)[key] = from[key] as any;
    }
    return to as T & U;
}